#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>

#define BUF 256

int kc_note(int fd)
{
	int flag = 0,line=0;
	
	int aster_slash_start = 0;
	int aster_slash_end = 0;

	char buffer[32]={0};
	char b_buf[8]={0};
	while(read(fd,buffer,1)>0){
	//	printf("flag = %d %c\n",flag,buffer[0]);
		switch(buffer[0]){
		case '/':
			switch(flag){
			case 0:
				b_buf[0]=buffer[0];
				flag = 1;
				break;
			case 1:
				break;
			case 2;
				break;
			case 3:
				break;
			case 4:
				break;
			}
			break;
		case '*':
			switch(flag){
			case 0:
				b_buf[0]=buffer[0];
				flag = 1;
				break;
			case 1:
				break;
			case 2;
				break;
			case 3:
				break;
			case 4:
				break;
			}
			break;
		}

#if 0
		switch(flag){
		case 0:
			if(buffer[0]=='/'){
				b_buf[0] = buffer[0];
				flag = 1;
				continue;
			}
			break;
		case 1:
			if(buffer[0]=='*'){
				flag = 2;
				continue;
			}
			printf("%c",b_buf[0]);
			printf("%c",buffer[0]);
			flag = 0;
			break;
		case 2:
			if(buffer[0] == '*'){
				flag = 3;
			}
			continue;
			break;
		case 3:
			if(buffer[0] == '/'){
				flag = 0;
				continue;
			}else if(buffer[0] == '*'){
				flag = 3;
				continue;
			}
			flag = 2;
			continue;
			break;
		case 4:
			break;
		}
		printf("%c",buffer[0]);
#endif
	}	
	return 0;
}

int main(int argc,char *argv[])
{
	int fd,i,total=0,ret;
	char buffer[BUF];
//	printf("argv[1] = %s\n",argv[1]);	
	fd  = open(argv[1],O_RDONLY);
	if(-1 == fd){
		perror("open file");
		return 0;
	}
	ret = kc_note(fd);
	while((i=read(fd,buffer,BUF))>0){
		printf("***************\n");
		total +=i;
	}
	
	printf("The total charactet in <<%s>> is %d\n",argv[1],total);

	return 0;
}
